package org.paraj.mapreduce;

import java.util.Collection;

public class AverageAggregator implements ResultAggregator<Double, Double>{
    
    public Double aggregate(Collection<Double> results){
        System.out.println("Running aggregation for " + results);
        return average(results);
    }

    private Double average(Collection<Double> results){
        if (results.size() == 0) return 0d;
        Double sum = 0d;
        for(Double e: results) sum+=e;
        return sum/results.size();
    }
}
